package com.hframe.typefilter;

import org.apache.log4j.Logger;

import java.security.MessageDigest;


/**
 * Base64加密
 * 
 * @author Administrator
 *
 */
public class Md5Encoder implements  FilterRef<Object, String> {
	static Logger log = Logger.getLogger(Md5Encoder.class);

	@Override
	public Object filter(String object) {
		return encoder(object);
	}

	public static String encoder(String object) {
		MessageDigest md;
		try {
			md = MessageDigest.getInstance("MD5");
			byte[] b = md.digest(object.getBytes("utf-8"));
			return ByteArrayToHex.toHexString(b);
		} catch (Exception e) {
			log.error(e, e);
			return "";
		}
	}
 
	public static String encoder(byte[] b) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			b = md.digest(b);
			return ByteArrayToHex.toHexString(b);
		} catch (Exception e) {
			log.error(e, e);
			return "";
		}
	}
}